package com.atguigu.ssyx.product.api;

import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.product.service.CategoryService;
import com.atguigu.ssyx.product.service.SkuInfoService;
import com.atguigu.ssyx.vo.product.SkuInfoVo;
import com.atguigu.ssyx.vo.product.SkuStockLockVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * ClassName: ProductInnnerController
 * Package: com.atguigu.ssyx.product.api
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-09-27
 * Time: 11:29
 */

@RestController
@RequestMapping("/api/product")
public class ProductInnnerController {
    //远程调用的接口 内部调用 这个路径和前端无关

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private SkuInfoService skuInfoService;

    //根据分类Id获取分类信息
    @GetMapping("/inner/getCategory/{categoryId}")
    public Category getCategory(@PathVariable Long categoryId) {
        //之前返回封装Result是为了方便前端 现在内部调用 直接返回查询结构就行了
        Category byId = categoryService.getById(categoryId);
        return byId;
    }

    //根据skuId获取分类信息
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {
        return skuInfoService.getById(skuId);
    }

    //根据skuId列表得到Sku信息列表
    //activity-规则中调用的
    @PostMapping("/inner/findSkuInfoList")
    public List<SkuInfo> findSkuInfoList(@RequestBody List<Long> skuIdList) {
        return skuInfoService.findSkuInfoList(skuIdList);
    }

    //根据关键字匹配sku列表
    @GetMapping("/inner/findSkuInfoKeyword/{keyword}")
    public List<SkuInfo> findSkuInfoByKeyword(@PathVariable("keyword") String keyword) {
        return skuInfoService.findSkuInfoByKeyword(keyword);
    }

    //根据分类Id 获取分类信息列表
    @PostMapping("inner/findCategoryList")
    public List<Category> getCategoryList(@RequestBody List<Long> categoryIdList) {
        //接口写完之后 定义
        return categoryService.listByIds(categoryIdList);
    }

    //获取所有分类
    @GetMapping("/inner/findAllCategoryList")
    public List<Category> findAllCategoryList(){
        List<Category> categoryList = categoryService.list();
        return categoryList;
        //远程调用接口 写完之后 定义
    }


    //获取新人专享商品
    @GetMapping("/inner/findNewPersonSkuINfoList")
    public List<SkuInfo> findNewPersonSkuInfoList(){

        List<SkuInfo> list = skuInfoService.findNewPersonSkuInfoList();
        return list;

    }

    //根据skuId获取sku信息
    @GetMapping("/inner/getSkuInfoVo/{skuId}")
    public SkuInfoVo getSkuInfoVo(@PathVariable Long skuId){
        return skuInfoService.getSkuInfoVo(skuId);
        //接口完成创建 最后要在client中定义
    }


    //验证和锁定库存
    @ApiOperation(value = "锁定库存")
    @PostMapping("/inner/checkAndLock/{orderNo}")
    public Boolean checkAndLock(@RequestBody List<SkuStockLockVo> skuStockLockVoList,
                                @PathVariable String orderNo){
        return skuInfoService.checkAndLock(skuStockLockVoList,orderNo);

    }


}
